package cayte.demo.dict;

import android.content.Context;

public class XfTTSHandler {

	public static final int SUCCESS = 0;
	public static final int ERROR_NO_TTS = 1;

	private XfTTS tts = null;
	private Context con;
	public boolean isEnable = true;

	public XfTTSHandler(Context context) {
		this.con = context.getApplicationContext();
	}

	public int initTTS() {
		tts = new XfTTS(con);
		if (tts == null) {
			isEnable = false;
			return ERROR_NO_TTS;
		}
		if (-1 == tts.initTTSLib(1)) {
			isEnable = false;
			return ERROR_NO_TTS;
		}
		tts.SetParam(1, 10000);
		isEnable = true;
		return SUCCESS;
	}

	public void stop() {
		if (isEnable)
			tts.ttsStop();
	}

	public void end() {
		if (isEnable) {
			tts.ttsStop();
			tts.ttsEnd();
		}
	}

	public void speak(String content) {
		if (isEnable) {
			tts.ttsStop();
			tts.playText(content);
		}
	}
}
